#include "headfiles.h"

using namespace std;

int main(int argc, char **argv) {
    if (argc != 3) {
        cout << "Usage: " << argv[0] << " file width" << endl;
        return 0;
    }

    int width = atoi(argv[2]);
    fstream fs;
    fs.open(argv[1], iostream::in);
    if (!fs.is_open()) {
        cout << "File " << argv[1] << " open error!" << endl;
        return 1;
    }

    vector<string> words;
    string str;
    while (fs >> str) {
        if (str.empty()) {
            break;
        }

        words.push_back(str);
    }
    fs.close();

    vector<string> format_lines;
    format_lines = fullJustify(words, width);

    for (auto it = format_lines.begin(); it != format_lines.end(); it++) {
        cout << *it << endl;
    }

    return 0;
}
